/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wanhai.itm.util;

import com.wanhai.util.UserBean;
import com.wanhai.util.UserInfoUtil;
import javax.servlet.http.HttpSession;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.http.SimpleSession;

/**
 *
 * @author m2434
 */
public class LoginService {
    public UserBean _user = new UserBean("123");
    String user_code="M2434";
    String office_code="TWTPE01";
    String prog_code="WDCMS101";
    String prog_name="MAINTAIN AREA CODE";
    String time_diff="0";
    
    SimpleSession s = (SimpleSession) Executions.getCurrent().getDesktop().getSession();
    HttpSession session = (HttpSession) s.getNativeSession();
    
    @Init
    public void init(){
        if(!checkLogin()) login();
    }
    
    public void login(){
        _user.setUserCode(user_code);
        _user.setOfficeCode(office_code);
        _user.setProgramName(prog_code,prog_name);
        _user.setTimeDiff(time_diff);
        
        
        session.setAttribute("LOGIN_USER", _user);
    }
    
    public boolean checkLogin(){
        if(session.getAttribute("LOGIN_USER") != null){
            return true;
        }
        
        return false;
    }
}
